package com.compass.doctor.ui.patient.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.compass.doctor.R
import com.compass.doctor.callback.OnCustomButtonClick
import com.compass.framework.model.PatientInfo
import com.compass.doctor.databinding.LayoutPatientItemBinding
import com.compass.framework.adapter.BaseBindViewHolder
import com.compass.framework.adapter.BaseRecyclerViewAdapter
import com.compass.framework.ext.gone
import com.compass.framework.ext.onClick
import com.compass.framework.ext.visible
import com.compass.framework.glide.setUrlCircle
import com.compass.framework.model.Tag
import com.compass.framework.utils.getDrawableResource

/**
 * Description： 患者Adapter
 * Date:2023/11/15 15:48
 */
class PatientAdapter(private var comeType:Int) : BaseRecyclerViewAdapter<PatientInfo, LayoutPatientItemBinding>() {

    lateinit var adapter: PatientTagAdapter
    private var onCustomBottomClick: OnCustomButtonClick?=null


    fun setBottomClick(bottomClick: OnCustomButtonClick?){
        onCustomBottomClick=bottomClick
    }

    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<LayoutPatientItemBinding>,
        item: PatientInfo?,
        position: Int
    ) {
        if (item == null) return
        holder.binding.apply {
            tvName.text = item.name
            tvAge.text = item.patientAge
            ivHead.setUrlCircle(item.avatar)
            ivSex.background= if (item.sex==1) getDrawableResource(R.mipmap.icon_male) else  getDrawableResource(
                R.mipmap.icon_female)
            rcyTag.layoutManager = LinearLayoutManager(rcyTag.context, LinearLayoutManager.HORIZONTAL, false)
            adapter = PatientTagAdapter()
            rcyTag.adapter = adapter
            if (item.tags.isNullOrEmpty()){
                item.tags?.add(Tag(1,"暂无标签"))
            }
            adapter.setData(item.tags)
            tvCommunication.onClick {
                onCustomBottomClick?.onButtonCallBack(position,"communication")
            }
            if (comeType==0) tvCommunication.visible() else tvCommunication.gone()

        }
    }

    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): LayoutPatientItemBinding {
        return LayoutPatientItemBinding.inflate(layoutInflater, parent, false)
    }
}